package com.tbit.uqbike.webmanager.controller;

import com.github.pagehelper.PageInfo;
import com.tbit.uqbike.object.pojo.UserPhoneLog;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.UserPhoneLogService;
import com.tbit.uqbike.webmanager.util.ServletUtils;
import com.tbit.uqbike.webmanager.util.excel.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户手机号码变动日志Controller
 *
 * @author jing
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/userPhoneLog")
public class UserPhoneLogController extends BaseController {
    @Autowired
    private UserPhoneLogService userPhoneLogService;


    /**
     * 查询用户手机号码变动日志列表
     */
    @GetMapping("/list")
    public JsonResult list(UserPhoneLog userPhoneLog) {
        PageInfo<UserPhoneLog> pageInfo = userPhoneLogService.selectUserPhoneLogListPage(userPhoneLog);
        return JsonResult.ok(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 导出手机号码更换记录
     */
    @GetMapping("/export")
    public JsonResult export(UserPhoneLog userPhoneLog) {
        List<UserPhoneLog> userPhoneLogList = userPhoneLogService.selectUserPhoneLogList(userPhoneLog);
        ExcelUtil<UserPhoneLog> util = new ExcelUtil<>(UserPhoneLog.class);
        return util.exportExcel(userPhoneLogList, "号码变动日志");
    }

    /**
     * 删除用户手机号码变动日志
     */
    @DeleteMapping("/{userIds}")
    public JsonResult remove(@PathVariable Integer[] userIds) {
        return JsonResult.toAjax(userPhoneLogService.deleteUserPhoneLogByIds(userIds), getLogin(ServletUtils.getRequest()).context);
    }
}
